<?php
include_once 'config/common.php';
class register extends common{
	//验证注册
	function regist($param){
		
		extract($param);
		
              /* if(empty($userName))
                {
                    $userName = $this->get_random_username(8);
                }*/
		//验证电话格式是否正确
		if(preg_match("/^1[34578]\d{9}$/",$phoneNumber)){    
		       $sql="users where phoneNumber='".$phoneNumber."'";
		       $user=$this->getInfo($sql, 'id');
		   if($user['id']!=''){
			   $msg='用户已被注册';
			   $error='1';
		   }else{
			   $msg='用户可用';
			   $error='0';
			   
				   //验证密码是否一致
				$password=trim($password);
				$repassword=trim($repassword);
				if(preg_match("/^[a-zA-Z\d_]{6,}$/",$password)){
					if($repassword!=$password){
						$msg='两次密码不一致';
						$error='3';
					}else{
						$msg='验证通过';
						$error='0';
						//验证通过插入数据库
						$data = array('phoneNumber'=>"$phoneNumber",'userName'=>"$userName",'password'=>md5($password),'reg_date'=>date("y-m-d",time()));
		                $this->insert('users',$data);
					}
				}else{
					$msg='密码长度小于六位';
					$error='3';
				}
		   }  
        }else{ 
				$msg='手机号格式不正确';
				$error='2';
        }
		
		
		return array('user_id'=>$user['id'],'error'=>$error,'msg'=>$msg);
	}
}
?>